﻿using Autofac;
using System.Reflection;

namespace BW.MesProject.Production.Host
{
    public class AutoFac:Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            //加载基础设施层程序集
            var assembly = Assembly.Load("BW.MesProject.Production.Infrastructure");
            //注册所有以Services结尾的类型为其实现的接口，生命周期为每请求一个实例
            builder.RegisterAssemblyTypes(assembly)
                .Where(t => t.Name.EndsWith("Services"))
                .AsImplementedInterfaces()
                .InstancePerDependency();

            //加载应用层程序集
            var assembly1 = Assembly.Load("BW.MesProject.Production.Application");

            //注册所有以Services结尾的类型为其实现的接口，生命周期为每请求一个实例
            builder.RegisterAssemblyTypes(assembly1)
                .Where(t => t.Name.EndsWith("Services"))
                .AsImplementedInterfaces()
                .InstancePerDependency();

            //调用基类的Load方法
            base.Load(builder);
        }
    }
}
